unit smryRptPro;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Rptbs, RzButton, ComCtrls, StdCtrls, Buttons, ExtCtrls,
  frxClass, frxPreview, frxExportPDF, frxExportXML, frxExportXLS,
  frxExportHTML, frxExportTXT, frxExportRTF, frxExportImage, frxBarcode,
  frxBDEComponents, frxCross, frxDMPExport, frxOLE, frxDCtrl, frxChart,
  frxRich, frxDesgn, frxGZip, frxDBSet, DB, ADODB, StrUtils;

type
  TsmryRptProfrm = class(TRptbsfrm)
    procedure FormCreate(Sender: TObject);
    procedure RzBitBtn2Click(Sender: TObject);
    procedure RzBitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure FrmExit;override;
    procedure refreshDB;
  end;

var
  smryRptProfrm: TsmryRptProfrm;

implementation

{$R *.dfm}

uses
  includefile, dbmodule;

procedure TsmryRptProfrm.refreshDB;
var
  starttime,endtime:TDateTime;
  rfid:string;
begin
  starttime:=strdtpicker.DateTime;
  endtime:=enddtpicker.DateTime;
  rfid:=Trim(LeftStr(comboRFID.Text,10));

  with dbRpt do begin
    Active:=False;
    SQL.Clear;
    SQL.Add(Format('Select RECORD.PRODUCTID,Right(RECORD.RFID,%d) as RFID,',[RFIDLen]));
    SQL.add('RECORD.SCALEID,EMPLOYEE.NAME,SUM(RECORD.TRAYS) as TRAYS,');
    SQL.Add('CONTRACTOR.NAME as CNAME,');
    SQL.Add('SUM(RECORD.NW) as NW,SUM(RECORD.GW) as GW from RECORD,EMPLOYEE,CONTRACTOR');
    SQL.Add('Where RECORD.RFID=EMPLOYEE.RFID');
    SQL.Add('And CONTRACTOR.ID=EMPLOYEE.CONTRACTORNAME');
    SQL.Add('Group by PRODUCTID,RECORD.RFID,SCALEID,EMPLOYEE.NAME,CONTRACTOR.NAME');
    SQL.Add('Order by RECORD.RFID');
    execsql;
    Active:=True;
  end;
  RptDs.UserName:='RECORD';
  
end;

procedure TsmryRptProfrm.FrmExit;
begin
  hide;
end;

procedure TsmryRptProfrm.FormCreate(Sender: TObject);
var
  I:integer;
begin
  inherited;
  for I:=0 to ComponentCount-1 do begin
    if Components[I] is TLabel then begin
      if 0<>TLabel(Components[I]).Tag then
        TLabel(Components[I]).Caption:=
                GetCaption(name,TLabel(Components[I]).Tag);
    end;
    if Components[I] is TRzBitBtn then begin
      if 0<>TRzBitBtn(Components[I]).Tag then
        TRzBitBtn(Components[I]).Caption:=
                GetCaption(name,TRzBitBtn(Components[I]).Tag);
    end;
  end;
  dbmodulefrm.getRFIDName(comboRFID.Items);
  comboRFID.Items.Insert(0,'All');
  comboRFID.ItemIndex :=0;
end;

procedure TsmryRptProfrm.RzBitBtn2Click(Sender: TObject);
begin
  inherited;
  refreshDB;
  frxReport.DesignReport;
end;

procedure TsmryRptProfrm.RzBitBtn1Click(Sender: TObject);
begin
  inherited;
  refreshDB;
end;

end.
